package com.wink.admin.config;

/**
 * 主从自动路由插件，读写分离可以利用插件
 *
 * @author xw
 * @date 2020-11-23 16:35
 */
// @Intercepts({@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
//         @Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
// @Slf4j
// public class MasterSlaveAutoRoutingPlugin implements Interceptor {
//
//     private static final String MASTER = "master";
//
//     private static final String SLAVE = "slave";
//
//     @Override
//     public Object intercept(Invocation invocation) throws Throwable {
//         Object[] args = invocation.getArgs();
//         MappedStatement ms = (MappedStatement) args[0];
//         try {
//             DynamicDataSourceContextHolder.push(SqlCommandType.SELECT == ms.getSqlCommandType() ? SLAVE : MASTER);
//             return invocation.proceed();
//         } finally {
//             DynamicDataSourceContextHolder.clear();
//         }
//     }
//
//     @Override
//     public Object plugin(Object target) {
//         return target instanceof Executor ? Plugin.wrap(target, this) : target;
//     }
//
//     @Override
//     public void setProperties(Properties properties) {
//     }
// }
